package com.ruoyi.location.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.location.repository.TeamRepository;
import com.ruoyi.location.service.AppService;
import com.ruoyi.location.vo.req.TeamCreateReq;
import com.ruoyi.location.vo.req.TeamDeleteReq;
import com.ruoyi.location.vo.req.TeamUpdateReq;
import com.ruoyi.location.vo.resp.UserLocationLatestResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/location/team/")
public class TeamController extends BaseController {

    @Autowired
    private TeamRepository teamRepository;
    @Autowired
    private AppService appService;

    @GetMapping("/list")
    public Object listMyTeam() {
        return teamRepository.listTeamByUserId();
    }

    @PostMapping("/create")
    public Object create(@RequestBody TeamCreateReq req) {
        return appService.create(req);
    }

    @PostMapping("/update")
    public Object update(@RequestBody TeamUpdateReq req) {
        return appService.update(req);
    }

    @PostMapping("/delete")
    public Object delete(@RequestBody TeamDeleteReq deleteReq) {
        appService.deleteTeam(deleteReq.getId());
        return success();
    }

    @PostMapping("/quit")
    public Object quit(@RequestBody TeamDeleteReq deleteReq) {
        appService.quitTeam(deleteReq.getId());
        return success();
    }

    @GetMapping("/createShareLink")
    public Object createShareLink(@RequestParam Long teamId) {
        return appService.createShareLink(teamId);
    }

    @GetMapping("/join")
    public Object joinTeam(@RequestParam Long teamId) {
        appService.joinTeam(teamId);
        return success();
    }

    @GetMapping("/listLatestLocation")
    public Object listLatestLocationByTeamId(@RequestParam Long teamId) {
        List<UserLocationLatestResp> result = appService.listLatestLocationByTeamId(teamId);
        return result;
    }
}
